import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "../views/layout/Layout";
import ParentView from "@/components/ParentView";

/**
 * hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
 *                                if not set alwaysShow, only more than one route under the children
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
 **/
export const constantRouterMap = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true
  },
  { path: "/404", component: () => import("@/views/404"), hidden: true },
  {
    path: "",
    component: Layout,
    redirect: "/home",
    children: [
      {
        path: "home",
        name: "home",
        component: () => import("@/views/home/index"),
        meta: { title: "首页", icon: "home" }
      }
    ]
  }
];

export const asyncRouterMap = [
  {
    path: "/member",
    name: "member",
    component: Layout,
    redirect: "/member/list",
    meta: { title: "会员管理" },
    children: [
      {
        path: "list",
        name: "member-list",
        component: () => import("@/views/member/list/index"),
        meta: { title: "会员列表" }
      },
      {
        path: "grade",
        name: "member-grade",
        component: () => import("@/views/member/grade/index"),
        meta: { title: "会员等级" }
      },
      {
        path: "sign",
        name: "member-sign",
        component: () => import("@/views/member/sign/index"),
        meta: { title: "签到列表" }
      }
    ]
  },
  {
    path: "/transaction",
    name: "transaction",
    component: Layout,
    redirect: "/transaction/orders",
    meta: { title: "交易管理" },
    children: [
      {
        path: "transaction-orders",
        name: "transaction-orders",
        component: () => import("@/views/transaction/orders/index"),
        meta: { title: "订单列表" }
      },
      {
        path: "transaction-recharge",
        name: "transaction-recharge",
        component: () => import("@/views/transaction/recharge/index"),
        meta: { title: "充值管理" }
      },
      {
        path: "transaction-case",
        name: "transaction-case",
        component: () => import("@/views/transaction/case/index"),
        meta: { title: "提现管理" }
      },
      {
        path: "transaction-control",
        name: "transaction-control",
        component: () => import("@/views/transaction/control/index"),
        meta: { title: "交易控制" }
      }
    ]
  },
  {
    path: "/goods",
    name: "goods",
    component: Layout,
    redirect: "/goods/list",
    meta: { title: "广告管理" },
    children: [
      {
        path: "goods-list",
        name: "goods-list",
        component: () => import("@/views/goods/list/index"),
        meta: { title: "广告列表" }
      },
      {
        path: "goods-classify",
        name: "goods-classify",
        component: () => import("@/views/goods/classify/index"),
        meta: { title: "广告分类" }
      }
    ]
  },
  {
    path: "/config",
    name: "config",
    component: Layout,
    redirect: "/config/service",
    meta: { title: "通知管理" },
    children: [
      {
        path: "config-service",
        name: "config-service",
        component: () => import("@/views/config/service/index"),
        meta: { title: "客服配置" }
      },
      {
        path: "config-coupon",
        name: "config-coupon",
        component: () => import("@/views/config/coupon/index"),
        meta: { title: "优惠劵" }
      }
    ]
  },
  {
    path: "/ums",
    component: Layout,
    redirect: "/ums/admin",
    name: "ums",
    meta: { title: "系统管理", icon: "ums" },
    children: [
      {
        path: "admin",
        name: "admin",
        component: () => import("@/views/ums/admin/index"),
        meta: { title: "用户管理", icon: "ums-admin" }
      },
      {
        path: "role",
        name: "role",
        component: () => import("@/views/ums/role/index"),
        meta: { title: "角色管理", icon: "ums-role" }
      },
      {
        path: "menu",
        name: "menu",
        component: () => import("@/views/ums/menu/index"),
        meta: { title: "菜单管理", icon: "ums-menu" }
      },
      {
        path: "login-log",
        name: "login-log",
        component: () => import("@/views/ums/log/login/index"),
        meta: { title: "登录日志", icon: "ums-menu" }
      },
      {
        path: "resource-category",
        name: "resource-category",
        component: () => import("@/views/ums/resource/categoryList"),
        meta: { title: "资源分类" },
        hidden: true
      },
      {
        path: "alloc-resource",
        name: "alloc-resource",
        component: () => import("@/views/ums/role/components/allocResource"),
        meta: { title: "分配资源" },
        hidden: true
      }
    ]
  },
  { path: "*", redirect: "/404", hidden: true }
];

export default new Router({
  base: "/",
  // mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
});
